<?php
class MyDB{
    private $db;//这里可能是pdo 可能是别的，仅仅为了演示
    public function __construct($connInfo)
    {
        //略
    }
    public function queryForRows($sql){
        return ['user_id'=>101,"user_name"=>"shenyi"];
    }
}

class MyUser{//老大
    private $mydb;
    public function __construct(MyDB $DB)
    {
        $this->mydb=$DB;
        //$this->mydb=new MyDB($dsn);//主动实例化DB
    }
    public function getAllUsers():array{//业务方法
        return $this->mydb->queryForRows("select * from users");
    }
}
//MyUser --> mydb
//mydb ->myuser  控制顺序发生了反转
$db=new MyDB("mysql:host=localhost");//和myuser地位平等
$user=new MyUser($db);
var_dump($user->getAllUsers());
